package com.century.sjt.adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.century.sjt.R;
import com.century.sjt.entity.BankCard;
import com.century.sjt.entity.Shops;
import com.century.sjt.util.Constant;

import java.util.List;

/**
 * Created by asus on 2016/9/2.
 */
public class ChooseShopAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    // 映射数据
    private List<Shops> mDataList;
    private Context context;
    private String recommendName;
    private Handler mHandler;


    public ChooseShopAdapter(Context context, List<Shops> list, Handler mHandler) {
        this.context = context;
        mLayoutInflater = LayoutInflater.from(context);
        this.mDataList = list;
        this.mHandler = mHandler;
    }

    // 获取数据量
    @Override
    public int getCount() {
        return mDataList.size();
    }

    // 获取对应ID项对应的Item
    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    // 获取对应项ID
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();

            //由于我们只需要将XML转化为View，并不涉及到具体的布局，所以第二个参数通常设置为null
            convertView = mLayoutInflater.inflate(R.layout.sjt_choose_shop_item, null);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.icon_select = (TextView) convertView.findViewById(R.id.icon_select);
            Typeface iconfont = Typeface.createFromAsset(context.getAssets(), "iconfont.ttf");
            holder.icon_select.setTypeface(iconfont);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.name.setText(mDataList.get(position).getShopName());
        if (mDataList.get(position).isSelect()){
            holder.icon_select.setText(context.getResources().getString(R.string.icon_select2));
        }else {
            holder.icon_select.setText(context.getResources().getString(R.string.icon_unselected));
        }
        return convertView;
    }
    // ViewHolder用于缓存控件
    class ViewHolder {
        public TextView name;
        public TextView icon_select;

    }
}
